<template>
	<view>
		<view class="main">
			<view class="shuru">
				<text class="shuru_tit t1">头像</text>
				<!-- <view class="cy_img">
				<image :src="item.headUrl" mode="aspectFill"></image>
				</view> -->
				<view class="shuru_image" @click="chooseImage">
					<!-- <block v-if="imageSrc"> -->
						<image :src="imageSrc" class="image" mode="aspectFill"></image>
					<!-- </block> -->
				</view>
			</view>
			<view class="shuru">
				<text class="shuru_tit t1">名称</text>
				<input type="text" class="shuru_text t1" value="" v-model="ids" placeholder="请输入昵称" />
			</view>
			
		<!-- 	<view class="shuru">
				<text class="shuru_tit t1">支付宝账号</text>
				<input class="shuru_text t1" type="text" placeholder="请输入支付宝账号" v-model="zfbid"></input>
			</view>
			<view class="shuru">
				<text class="shuru_tit t1">支付宝用户名</text>
				<input class="shuru_text t1" type="text" placeholder="请输入支付宝用户名" v-model="zfbname"></input>
			</view>
			<view class="shuru">
				<text class="shuru_tit t1">微信账号</text>
				<input class="shuru_text t1" type="text" placeholder="请输入微信账号" v-model="wxid"></input>
			</view> -->
		</view>
		<view class="tuic t2" @click="info()">修改</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				mainid: '',
				imageSrc: '',
				imageSrcid:'',
				imageSrcid1:'',
				ids: '',
				ids1: '',
				index: 0,
				zfbid:'',
				zfbname:'',
				wxid:'',
				zfbid1:'',
				zfbname1:'',
				wxid1:'',
				utype : ""
			}
		},
		onLoad(param) {
			console.log("param",param);
			this.utype = param.utype;
			this.imageSrc = '';
	
			var _this = this;	
			uni.getStorage({
				key: 'user',
				success: function(res) {
					_this.mainid = res.data.id;
					_this.myinfo();
				}
			});
		},
		methods: {
		
		tup(id) {
			var _this = this;
			uni.request({
				header: {
					'Content-Type': 'application/json', //自定义请求头信息
				},
				url: getApp().globalData.url + 'file/getFile', //仅为示例，并非真实接口地址。
				method: 'POST',
				data: {
					id: id
				},
				success: (res) => {
					console.log(res);
					uni.hideLoading(); //关闭加载动画
					if (res.data.status == '200') {
							_this.imageSrc = res.data.data.domain + res.data.data.localPath; //产品图片
							console.log(_this.imageSrc);
					}
				},
				fail: (error) => {
					// this.checks = true
					console.log(error)
				}
			});
		},
		chooseImage: function() {
			if(this.utype == "20"){
				return;
			}
			var _this = this;
			uni.chooseImage({
				count: 1,
				sizeType: ['compressed'],
				sourceType: ['album'],
				success: function(res) {
					console.log(res);
					var tempFilePaths = res.tempFilePaths;
					// console.log(tempFilePaths);
					var uploadTask = uni.uploadFile({
						url: getApp().globalData.url + 'file/upload',
						filePath: tempFilePaths[0],
						name: 'file',
						formData: {},
						success: function(uploadFileRes) {
							// console.log(uploadFileRes);
							var datamain = JSON.parse(uploadFileRes.data);
							console.log(datamain);
							if (datamain.status == 200) {
								var url = datamain.data.domain + datamain.data.localPath;
								_this.imageSrc = url;
								_this.imageSrcid = datamain.data.id;
								console.log(url);
							} else {
								uni.showToast({
									title: datamain.msg,
									icon: 'none',
									duration: 1000
								})
							}
						}
					});
		
				},
				error: function(e) {
					console.log(e);
					uni.showToast({
						title: '上传失败',
						icon: 'none',
						duration: 1000
					})
				}
			});
		
		},
			info() {
				var _this = this;
				
				console.log(_this.mainid,_this.imageSrcid,_this.ids);
				// console.log(_this.qbid);
				if (_this.checks === false) {
					return false
				}
				if (_this.ids==_this.ids1&&_this.imageSrcid==_this.imageSrcid1&&_this.zfbid==_this.zfbid1&&_this.zfbname==_this.zfbname1&&_this.wxid==_this.wxid1) {
	
					uni.showToast({
						title: '用户信息无任何修改',
						icon: 'none',
						duration: 2000
					});
					return false
				}
				if (!_this.imageSrcid) {
					uni.showToast({
						title: '请上传头像',
						icon: 'none',
						duration: 2000
					});
					return false
				}
				if (!_this.ids) {
	
					uni.showToast({
						title: '请输入昵称',
						icon: 'none',
						duration: 2000
					});
					return false
				}
	// 			if (!_this.zfbid) {
	
	// 				uni.showToast({
	// 					title: '请输入支付宝账号',
	// 					icon: 'none',
	// 					duration: 2000
	// 				});
	// 				return false
	// 			}
	// 			if (!_this.zfbname) {
	
	// 				uni.showToast({
	// 					title: '请输入支付宝用户名',
	// 					icon: 'none',
	// 					duration: 2000
	// 				});
	// 				return false
	// 			}
	// 			if (!_this.wxid) {
	
	// 				uni.showToast({
	// 					title: '请输入微信账号',
	// 					icon: 'none',
	// 					duration: 2000
	// 				});
	// 				return false
	// 			}
				_this.checks = false;
				// data:{
					
				// 		id: _this.mainid,
				// 		headId:_this.imageSrcid,//	头像		false	string
				// 		nickName:_this.ids,//	昵称		false	 string
				// 		alipayAccount:_this.zfbid,
				// 		alipayName:_this.zfbname,
				// 		wechatAccount:_this.wxid,
				// }
			uni.request({
				header: {
					'Content-Type': 'application/json', //自定义请求头信息
				},
				url: getApp().globalData.url + 'user/saveOrUpdateUserInfo', //仅为示例，并非真实接口地址。
				method: 'POST',
				data: {
					id: _this.mainid,
					headId:_this.imageSrcid,//	头像		false	string
					nickName:_this.ids,//	昵称		false	 string
					alipayAccount:'',
					alipayName:'',
					wechatAccount:'',
				},
				success: (res) => {
					_this.checks=true;
					console.log(res);
					uni.hideLoading(); //关闭加载动画
					console.log(res);
						 if(res.data.status==200){
							uni.showToast({
								title: '上传成功',
								icon: 'success',
								duration: 2000
							});
							setTimeout(function() {
								uni.navigateBack();
							}, 2000)
	
						} else {
					_this.checks=true;	
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 2000
							});
						}
					},
					fail: (error) => {
						this.checks = true
						console.log(error)
					}
				});
			},
			myinfo() {
				var that = this;
				uni.request({
					header: {
						'Content-Type': 'application/x-www-form-urlencoded', //自定义请求头信息
					},
					url: getApp().globalData.url + 'user/userInfo/' + that.mainid, //仅为示例，并非真实接口地址。
					method: 'POST',
					data: {
						id: that.mainid
					},
					success: (res) => {
						uni.hideLoading(); //关闭加载动画
						console.log(res);
						if (res.data.status == '200') {
							that.wxid = res.data.data.wechatAccount;
							that.wxid1=res.data.data.wechatAccount;	
							that.zfbid1 = res.data.data.alipayAccount;
							that.zfbname1=res.data.data.alipayName;	
							that.zfbid = res.data.data.alipayAccount;
							that.zfbname=res.data.data.alipayName;	
							that.ids = res.data.data.nickName;
							that.imageSrcid=res.data.data.headId;	
							that.ids1 = res.data.data.nickName;
							that.imageSrcid1=res.data.data.headId;
							that.tup(res.data.data.headId);
						}
					},
					fail: (error) => {
						// this.checks = true
						console.log(error)
					}
				});
			}
		}
	}
</script>

<style>
	.shuru {
		width: 100%;
		height: auto;
		display: block;
		float: left;
		border-radius: 1vw;
		overflow: hidden;
		padding: 2vw 4vw;
		background: #fff;
		margin-top: 3vw;
		box-shadow: 0px 0px 5px #eee;
	}

	.shuru_tit {
		width: 30%;
		height: 10vw;
		line-height: 10vw;
		display: block;
		float: left;
	}

	.shuru_text {
		width: 60%;
		height: 10vw;
		line-height: 10vw;
		display: block;
		float: right;
		text-align: right;
	}
	.shuru_image {
		width: 10vw;
		height: 10vw;
		display: block;
		float: right;
		border-radius: 2vw;
		overflow: hidden;
		background: #F2F2F2;
		border: 1px solid #F2F2F2;
	}
image.image{width: 100%;height: 100%;}
	/* .tuic {
		width: 90%;
		height: 14vw;
		display: block;
		float: left;
		text-align: center;
		line-height: 14vw;
		background: url(../../static/img/tuichu.png) no-repeat top center;
		background-size: 100%;
		margin: 0 5%;
		margin-top: 3vw;
	} */
</style>
